package Dao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import Controller.LoginController;
import Entity.Transfer;

public class ViewRequestDao {
	public static List<Transfer> searchApproval() throws IOException,
	ClassNotFoundException, SQLException {
String sql = "select * from Transfer where EmpNumber = '"+LoginController.name+"'";
List<Transfer> transferList = new Vector<Transfer>();
Connection con = DaoUtil.getConnection();
PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
ResultSet rs = stm.executeQuery();
while (rs.next()) {
	transferList.add(new Transfer(rs.getInt("ID"), rs.getString("EmpNumber"),
			rs.getString("EmpName"), rs.getString("FromLocation"), rs.getString("ToLocation"), rs.getString("FromProject"),rs.getString("ToProject"), rs.getString("FromDept"),rs.getString("ToDept")));
//	System.out.print(rs.getInt("ID") + rs.getString("EmpNumber")
//			+ rs.getString("EmpName") + rs.getString("ToLocation")
//			+ rs.getString("ToProject"));
}

DaoUtil.closeConnection(con);
return transferList;

}

public static Transfer selectTableLoad(int row) throws IOException,
	ClassNotFoundException, SQLException {
String sql = "select * from Transfer where ID = ? ";
Transfer transfer = new Transfer(row, null, null, null, null, null);
Connection con = DaoUtil.getConnection();
PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
stm.setInt(1, row);
ResultSet rs = stm.executeQuery();
while (rs.next()) {
	transfer = new Transfer(rs.getInt("ID"), rs.getString("EmpNumber"),
			rs.getString("EmpName"), rs.getString("FromLocation"), rs.getString("ToLocation"), rs.getString("FromProject"),rs.getString("ToProject"), rs.getString("FromDept"),rs.getString("ToDept"));
	// System.out.print(rs.getInt("ID")+ rs.getString("EmpNumber")+
	// rs.getString("EmpName")+ rs.getString("ToLocation")
	// +rs.getString("ToProject"));
}

DaoUtil.closeConnection(con);
return transfer;
}
}
